//
//  UIImageView+Additions.swift
//  live
//
//  Created by melvyn on 2018/8/17.
//  Copyright © 2018 NEET. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa
import Kingfisher
import Link

typealias Thumbnail = (String?, String?)
extension Reactive where Base: UIImageView {
    
    var image: Binder<Thumbnail> {
        return Binder(self.base, binding: { (view, metadata) in
            
            var url: URL? = nil
            var image: UIImage? = nil
            
            if let imageID = metadata.0, !imageID.isEmpty {
                url = URL.init(string: APIClient.Route.images.description + imageID)
            }
            
            if let named = metadata.1 {
                image = UIImage.init(named: named)
            }
            view.kf.setImage(with: url, placeholder: image)
        })
    }
}
